<?php

class manageController extends AdminController {

    public function init() {
        $this->tableName='page';
        parent::init();
    }
    public function indexAction() {
        $this->list=$this->model->order('ordernum asc,id desc')->getlist();
        $this->display();
    }

    public function addAction() {
        if(IS_POST){
            $param['name']=I('name','str','');
            $param['key']=I('key','en','');
            $param['litpic']=I('litpic','str','');
            $param['ordernum']=I('ordernum','int','');
            $param['type']=I('type','int',1);
            $param['status']=I('status','int',1);
            $param['content']=($param['type']==1)?text::simditor(I('content','str','')):I('htmlcontent','str','');
            if($this->model->add($param)){
                $this->success('添加成功',U('index'));
            }else{
                $this->error('添加失败');
            }
        }
        $this->display();
    }

    public function editAction() {
        $id=I('request.id','int',0);
        $info=$this->model->where(array('id'=>$id))->find();
        if (IS_POST){
            $param['name']=I('name','str','');
            $param['key']=I('key','en','');
            $param['litpic']=I('litpic','str','');
            $param['ordernum']=I('ordernum','int','');
            $param['type']=I('type','int',1);
            $param['status']=I('status','int',1);
            $param['content']=($param['type']==1)?text::simditor(I('content','str','')):I('htmlcontent','str','');
            $param['id']=$id;
            if ($this->model->edit($param)){
                $this->success('修改成功',U('index'));
            }else{
                $this->error('修改失败');
            }
        }
        $this->info=$info;
        $this->display();
    }
}